import * as React from "react"
import { type SearchParams } from "@/types/table"

import { getValidFilters } from "@/lib/data-table"
import { DataTableSkeleton } from "@/components/data-table/data-table-skeleton"
import { Shell } from "@/components/shell"

import { searchParamsTechVendorPossibleItemsCache } from "@/lib/tech-vendor-possible-items/validations"
import { getTechVendorPossibleItems, getUniqueTechVendorTypes } from "@/lib/tech-vendor-possible-items/service"
import { PossibleItemsDataTable } from "@/lib/tech-vendor-possible-items/table/possible-items-data-table"
import { TechVendorPossibleItemsContainer } from "@/components/tech-vendor-possible-items/tech-vendor-possible-items-container"

interface TechVendorPossibleItemsPageProps {
  searchParams: Promise<SearchParams>
}

export default async function TechVendorPossibleItemsPage(props: TechVendorPossibleItemsPageProps) {
  const searchParams = await props.searchParams
  const search = searchParamsTechVendorPossibleItemsCache.parse(searchParams)

  const validFilters = getValidFilters(search.filters)

  // 벤더 타입 정의
  const vendorTypes = [
    { id: "all", name: "전체", value: "" },
    { id: "ship", name: "조선", value: "조선" },
    { id: "top", name: "해양TOP", value: "해양TOP" },
    { id: "hull", name: "해양HULL", value: "해양HULL" },
  ]

  const promises = Promise.all([
    getTechVendorPossibleItems({
      ...search,
      filters: validFilters,
    }),
    getUniqueTechVendorTypes(),
  ])

  return (
    <Shell className="gap-4">
      <React.Suspense
        fallback={
          <DataTableSkeleton
            columnCount={7}
            searchableColumnCount={4}
            filterableColumnCount={1}
            cellWidths={["3rem", "10rem", "15rem", "12rem", "15rem", "20rem", "12rem"]}
            shrinkZero
          />
        }
      >
        <TechVendorPossibleItemsContainer vendorTypes={vendorTypes}>
          <PossibleItemsDataTable promises={promises} />
        </TechVendorPossibleItemsContainer>
      </React.Suspense>
    </Shell>
  )
} 